package com.sms.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.sms.common.A;
import com.sms.pojo.Categories;
import com.sms.service.impl.CategoriesServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//商品类别添加
@WebServlet("/CategoriesAdd")
public class CategoriesAddController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletInputStream inputStream = req.getInputStream();
        String s = IoUtil.readUtf8(inputStream);
        JSONObject obj = JSONUtil.parseObj(s);
        Categories categories=new Categories();
        BeanUtil.copyProperties(obj,categories);
        CategoriesServiceImpl service=new CategoriesServiceImpl();
        service.save(categories);
        service.getSqlSession().close();
        resp.getWriter().write(JSONUtil.toJsonStr(A.success("商品类别添加成功")));
    }
}
